import 'package:tot_android_flutter/eneity/user_entity.dart';

import '../eneity/AppResponse.dart';
import '../eneity/article_entity.dart';
import '../eneity/project_category_entity.dart';
import '../eneity/project_list_entity.dart';
import '../eneity/tree_item_entity.dart';
import 'NetworkManager.dart';
import 'api.dart';

class ApiService {
  // 静态变量，用于保存唯一的实例
  static final ApiService _instance = ApiService._internal();

  // 私有构造函数，防止外部直接实例化
  ApiService._internal();

  // 公共的静态方法，用于获取单例实例
  static ApiService get instance => _instance;

  Future<AppResponse<ArticleEntity>> articleList(int curPage) async {
    return await NetworkManager()
        .get<ArticleEntity>("${Api.homePageArticle}${curPage}/json");
  }

  Future<AppResponse<List<ProjectCategoryEntity>>> projectCategory() async {
    return await NetworkManager()
        .get<List<ProjectCategoryEntity>>(Api.projectCategory);
  }

  Future<AppResponse<ProjectListEntity>> projectList(
      int curPage, String cid) async {
    return await NetworkManager()
        .get<ProjectListEntity>("${Api.projectList}$curPage/json", params: {
      "cid": "${cid}",
    });
  }

  Future<AppResponse<List<TreeItemEntity>>> treeJson() async {
    return await NetworkManager().get<List<TreeItemEntity>>(Api.treeJson);
  }

  Future<AppResponse<UserEntity>> login(String userName, String pw) async {
    return await NetworkManager().post<UserEntity>(Api.login, params: {
      "username": userName,
      "password": pw,
    });
  }

}
